<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8"/>
	<link rel="apple-touch-icon" sizes="76x76" href="./assets/img/favicon.ico">
	<link rel="icon" type="image/png" href="./assets/img/favicon.ico">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
	<title>数据资产管理平台</title>
	<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no' name='viewport'/>

	<!-- Google Font -->
	<!-- <link href="https://fonts.googleapis.com/css?family=Nunito:300,300i,400,600,800" rel="stylesheet"> -->

	<!-- Main CSS -->
	<link href="./assets/css/main.css" rel="stylesheet"/>

	<!-- Animation CSS -->
	<link href="vendor/aos.css" rel="stylesheet"/>

</head>

<body>



<!-- Main -->
<div class="d-md-flex h-md-100 align-items-center">
	<div class="col-md-6 p-0 bg-indigo h-md-100" style="background-image: url(./assets/img/demo/banner1.jpg);background-size: cover;">
		<div class="text-white d-md-flex align-items-center h-100 p-5 text-center justify-content-center">
			<div class="logoarea pt-5 pb-5">
				<p>
					<!-- <i class="fa fa-anchor fa-3x"></i> -->
				</p>
				<h1 class="mb-0 mt-3 display-4">数据资产管理平台</h1>
				<h5 class="mb-4 font-weight-light"> <!-- <i class="fab fa-sass fa-2x text-cyan"></i> --></h5>

			</div>
		</div>
	</div>
	<div class="col-md-6 p-0 bg-white h-md-100 loginarea">
		<div class="d-md-flex align-items-center h-md-100 p-5 justify-content-center">
			<form class="border rounded p-5" id="form1">
				<h3 class="mb-4 text-center">登录</h3>
				<div class="form-group">
					<input type="text" class="form-control" id="InputEmail1" placeholder="账号" required="" />
				</div>
				<div class="form-group">
					<input type="password" class="form-control" id="InputPassword1" placeholder="密码" required="" />
				</div>
				<div class="form-group form-check">
					<input type="checkbox" class="form-check-input" id="exampleCheck1">
					<label class="form-check-label small text-muted" for="exampleCheck1">记住我</label>
				</div>
				<button class="btn btn-success btn-round btn-block shadow-sm" type="submit">提交</button>
				<small class="d-block mt-4 text-center">
					<a class="text-gray" href="./forgetPassword.html" style="float: left;">忘记密码?</a>
					<a class="text-gray" href="./register.html" style="float: right;">前往注册</a>
				</small>
			</form>
		</div>
	</div>
</div>
<!-- End Main -->


<!--------------------------------------
JAVASCRIPTS
--------------------------------------->
<script src="vendor/jquery.min.js" type="text/javascript"></script>
<script src="vendor/popper.min.js" type="text/javascript"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="js/functions.js" type="text/javascript"></script>
<script src="./assets/layui/layui.js" type="text/javascript"></script>
<script src="js/tool.js" type="text/javascript"></script>
<!-- Animation -->
<script src="vendor/aos.js" type="text/javascript"></script>
<noscript>
	<style>
		*[data-aos] {
			display: block !important;
			opacity: 1 !important;
			visibility: visible !important;
		}
	</style>
</noscript>
<script>
	AOS.init({
		duration: 700
	});
</script>

<!-- Disable animation on less than 1200px, change value if you like -->
<script>
	AOS.init({
		disable: function () {
			var maxWidth = 1200;
			return window.innerWidth < maxWidth;
		}
	});
</script>
<script>
	$(function (){
		$('#form1').on('submit', function (e) {
			let index = layer.load(1);
			e.preventDefault();
			let email = $("#InputEmail1").val();
			let password = $("#InputPassword1").val();
			if(email&&password){
				$.ajax({
					timeout:5000,
					type:'POST',
					url:window.Http+"/login",
					data:JSON.stringify({"username":email,"password":password}),
					contentType: 'application/json;charset=utf-8',
					success:function (res){
						if(res.code === 200){
							sessionStorage.setItem('Token', res.token);
							if(res.token){
								$.ajax({
									timeout:30000,
									type:'GET',
									url:window.Http+"/getInfo",
									headers: {
										'Authorization':"Bearer "+sessionStorage.getItem('Token')
									},
									success:function (userRes){
										if(res.code === 200){
											sessionStorage.setItem('userId',userRes.user.userId);
											sessionStorage.setItem('UserInfo',JSON.stringify(userRes.user));
											setTimeout(function () {
											   layer.close(index);
											   window.location.href = './index.html';
										   },1000)
											
										} else if (res.code == 401){
											layer.close(index);
											window.location.href = '../login.html';
										}
									},error:function (err){
										layer.close(index);
										layer.msg("服务器异常，请稍后重试");
									},
								})
							}



						}else{
							layer.msg(res.msg||"无法登陆，账号或密码错误");
						}
					},
					error:function(err){
						layer.msg("服务器异常");
					}
				})
			}
		})
		// 记住我
		$('#InputEmail1').val(localStorage.getItem('username1'))
		$('#InputPassword1').val(localStorage.getItem('password1'))
		$('#exampleCheck1').click(function(){
			if($('#exampleCheck1').is(':checked')){
				var username1=$('#InputEmail1').val()
				var password1=$('#InputPassword1').val()
				localStorage.setItem('username1',username1)
				localStorage.setItem('password1',password1)
			}else {
				localStorage.removeItem('username1');
				localStorage.removeItem('password1');
			}
		})
		function monitorStatus() {
			return new Promise(function (resolve, reject) {
				$.ajax({
					url: window.monitorHttp + 'api/v1/status',
					type: "POST",
					headers: {
						'Authorization': "Bearer " + sessionStorage.getItem('Token')
					},
					data:JSON.stringify({
						"Cmd":"Status",
						"Program":"Front",
					}),
					success: function (res) {
						const data=isJSON(res);
						if (data.Code === 200) {
							resolve(data)
						} else {
							layer.msg(data.Msg)
							layer.msg('连接监管程序失败')
							reject(new Error('连接监管程序失败'))
						}
					},
					error:function () {
						reject(new Error('连接监管程序失败'))
					}
				})
			})
		}

		/**
		 * @description:函数描述 登录监管程序
		 * @return Promise
		 */
		function monitorLogin(name,password) {
			return new Promise(function (resolve, reject) {
				$.ajax({
					url: window.monitorHttp +'api/v1/user/login',
					type: 'POST',
					headers: {
						'Authorization': "Bearer " + sessionStorage.getItem('Token'),
						'content-Type': "application/json;charset=utf-8"
					},
					data:JSON.stringify({
						Cmd:"Login",
						user: {
							name: name,
							password:password
						}
					}),
					success: function (res) {
						const data=isJSON(res);
						if (data.Code === 200) {
							resolve(data)
						} else {
							layer.msg(data.Msg)
							reject(new Error('登录监管程序失败'))
						}
					},
					error:function () {
						reject(new Error('登录监管程序失败'))
					}
				})
			})
		}
		/**
		 * @description:函数描述 判断是否是JSON 并返回js对象
		 * @return Object
		 * @param obj
		 */

		function isJSON(obj) {
			try {
				return JSON.parse(obj);
			} catch (e) {
				return obj;
			}
		}
		/**
		 * @description:函数描述 下载监管程序
		 * @return Promise
		 */

		function monitorDownload() {
			return new Promise(function (resolve, reject) {
				$.ajax({
					url: window.monitorDownloadHttp + 'api/v1/monitor/download',
					type: 'GET',
					// headers: {
					// 	'Authorization': "Bearer " + sessionStorage.getItem('Token')
					// },
					success: function (res) {
						const data=isJSON(res);
						if (data.Code === 200) {
							resolve(data)
						} else {
							reject(new Error('监管程序下载失败'))
						}
					},
					error:function () {
						reject(new Error('监管程序下载失败'))
					}
				})
			})
		}

	})

</script>
</body>
</html>
